Java源码示例:mx4j.tools.adaptor.http.HttpAdaptor

示例1
/**
 * Defines and starts the JMX Http Adaptor service from MX4J.
 * <p>
 * If {@link AgentConfig#isHttpEnabled} returns false, then this adaptor will
 * not be started.
 */
private void startHttpAdaptor() {
  if (!this.agentConfig.isHttpEnabled()) return;
  try {
    ObjectName objName = getHttpAdaptorName();

    // make sure this adaptor is not already registered...
    if (getMBeanServer().isRegistered(objName)) {
      // dunno how we got here...
      getLogWriterI18n().info(LocalizedStrings.AgentImpl_HTTPADAPTOR_ALREADY_REGISTERED_AS__0, objName);
      return;
    }

    this.httpAdaptor = new HttpAdaptor();

    // validate and set host and port values...
    if (this.agentConfig.getHttpPort() > 0) {
      this.httpAdaptor.setPort(this.agentConfig.getHttpPort());
      getLogWriterI18n().config(LocalizedStrings.AgentImpl_HTTP_ADAPTOR_LISTENING_ON_PORT__0, this.agentConfig.getHttpPort());
    }
    else {
      getLogWriterI18n().error(LocalizedStrings.AgentImpl_INCORRECT_PORT_VALUE__0, this.agentConfig.getHttpPort());
    }

    if (this.agentConfig.getHttpBindAddress() != null) {
      String host = this.agentConfig.getHttpBindAddress();
      getLogWriterI18n().config(LocalizedStrings.AgentImpl_HTTP_ADAPTOR_LISTENING_ON_ADDRESS__0, host);
      this.httpAdaptor.setHost(host);
    }
    else {
      getLogWriterI18n().error(LocalizedStrings.AgentImpl_INCORRECT_NULL_HOSTNAME);
    }

    // SSL support...
    MX4JServerSocketFactory socketFactory =
      new MX4JServerSocketFactory(
          this.agentConfig.isAgentSSLEnabled(),
          this.agentConfig.isHttpSSLRequireAuth(),
          this.agentConfig.getAgentSSLProtocols(),
          this.agentConfig.getAgentSSLCiphers(),
          getLogWriterI18n(),
          this.agentConfig.getGfSecurityProperties());
    this.httpAdaptor.setSocketFactory(socketFactory);

    // authentication (user login) support...
    if (this.agentConfig.isHttpAuthEnabled()) {
      // this pops up a login dialog from the browser...
      this.httpAdaptor.setAuthenticationMethod(
          MX4J_HTTPADAPTOR_BASIC_AUTHENTICATION); // only basic works

      this.httpAdaptor.addAuthorization(
          this.agentConfig.getHttpAuthUser(),
          this.agentConfig.getHttpAuthPassword());
    }

    // add the XsltProcessor...
    this.httpAdaptor.setProcessorName(createXsltProcessor());

    // register the HttpAdaptor and snap on the XsltProcessor...
    getMBeanServer().registerMBean(this.httpAdaptor, objName);
    this.httpAdaptor.start();
  } catch (Throwable t) {
    Error err;
    if (t instanceof Error && SystemFailure.isJVMFailureError(
        err = (Error)t)) {
      SystemFailure.initiateFailure(err);
      // If this ever returns, rethrow the error. We're poisoned
      // now, so don't let this thread continue.
      throw err;
    }
    // Whenever you catch Error or Throwable, you must also
    // check for fatal JVM error (see above).  However, there is
    // _still_ a possibility that you are dealing with a cascading
    // error condition, so you also need to check to see if the JVM
    // is still usable:
    SystemFailure.checkFailure();
    this.logWriter.error(LocalizedStrings.AgentImpl_FAILED_TO_START_HTTPADAPTOR__0, t.getMessage());
    throw new StartupException(LocalizedStrings.AgentImpl_FAILED_TO_START_HTTPADAPTOR__0.toLocalizedString(t.getMessage()), t);
  }
}
 
示例2
public void setHttpAdaptor(HttpAdaptor httpAdaptor) {
    this.httpAdaptor = httpAdaptor;
}
 
示例3
/**
 * Defines and starts the JMX Http Adaptor service from MX4J.
 * <p>
 * If {@link AgentConfig#isHttpEnabled} returns false, then this adaptor will
 * not be started.
 */
private void startHttpAdaptor() {
  if (!this.agentConfig.isHttpEnabled()) return;
  try {
    ObjectName objName = getHttpAdaptorName();

    // make sure this adaptor is not already registered...
    if (getMBeanServer().isRegistered(objName)) {
      // dunno how we got here...
      getLogWriterI18n().info(LocalizedStrings.AgentImpl_HTTPADAPTOR_ALREADY_REGISTERED_AS__0, objName);
      return;
    }

    this.httpAdaptor = new HttpAdaptor();

    // validate and set host and port values...
    if (this.agentConfig.getHttpPort() > 0) {
      this.httpAdaptor.setPort(this.agentConfig.getHttpPort());
      getLogWriterI18n().config(LocalizedStrings.AgentImpl_HTTP_ADAPTOR_LISTENING_ON_PORT__0, this.agentConfig.getHttpPort());
    }
    else {
      getLogWriterI18n().error(LocalizedStrings.AgentImpl_INCORRECT_PORT_VALUE__0, this.agentConfig.getHttpPort());
    }

    if (this.agentConfig.getHttpBindAddress() != null) {
      String host = this.agentConfig.getHttpBindAddress();
      getLogWriterI18n().config(LocalizedStrings.AgentImpl_HTTP_ADAPTOR_LISTENING_ON_ADDRESS__0, host);
      this.httpAdaptor.setHost(host);
    }
    else {
      getLogWriterI18n().error(LocalizedStrings.AgentImpl_INCORRECT_NULL_HOSTNAME);
    }

    // SSL support...
    MX4JServerSocketFactory socketFactory =
      new MX4JServerSocketFactory(
          this.agentConfig.isAgentSSLEnabled(),
          this.agentConfig.isHttpSSLRequireAuth(),
          this.agentConfig.getAgentSSLProtocols(),
          this.agentConfig.getAgentSSLCiphers(),
          getLogWriterI18n(),
          this.agentConfig.getGfSecurityProperties());
    this.httpAdaptor.setSocketFactory(socketFactory);

    // authentication (user login) support...
    if (this.agentConfig.isHttpAuthEnabled()) {
      // this pops up a login dialog from the browser...
      this.httpAdaptor.setAuthenticationMethod(
          MX4J_HTTPADAPTOR_BASIC_AUTHENTICATION); // only basic works

      this.httpAdaptor.addAuthorization(
          this.agentConfig.getHttpAuthUser(),
          this.agentConfig.getHttpAuthPassword());
    }

    // add the XsltProcessor...
    this.httpAdaptor.setProcessorName(createXsltProcessor());

    // register the HttpAdaptor and snap on the XsltProcessor...
    getMBeanServer().registerMBean(this.httpAdaptor, objName);
    this.httpAdaptor.start();
  } catch (Throwable t) {
    Error err;
    if (t instanceof Error && SystemFailure.isJVMFailureError(
        err = (Error)t)) {
      SystemFailure.initiateFailure(err);
      // If this ever returns, rethrow the error. We're poisoned
      // now, so don't let this thread continue.
      throw err;
    }
    // Whenever you catch Error or Throwable, you must also
    // check for fatal JVM error (see above).  However, there is
    // _still_ a possibility that you are dealing with a cascading
    // error condition, so you also need to check to see if the JVM
    // is still usable:
    SystemFailure.checkFailure();
    this.logWriter.error(LocalizedStrings.AgentImpl_FAILED_TO_START_HTTPADAPTOR__0, t.getMessage());
    throw new StartupException(LocalizedStrings.AgentImpl_FAILED_TO_START_HTTPADAPTOR__0.toLocalizedString(t.getMessage()), t);
  }
}
 
示例4
/**
 * @param idx Index.
 * @return MBean server.
 * @throws Exception If failed.
 */
private MBeanServer getMBeanServer(int idx) throws Exception {
    HttpAdaptor adaptor = new HttpAdaptor();

    MBeanServer srv = MBeanServerFactory.createMBeanServer();

    adaptor.setPort(Integer.valueOf(GridTestProperties.getProperty("discovery.mbeanserver.selftest.baseport")) +
        idx);

    srv.registerMBean(adaptor, new ObjectName(HTTP_ADAPTOR_MBEAN_NAME));

    adaptor.start();

    httpAdaptors.add(adaptor);

    return srv;
}
 
示例5
/**
 * @return Configured MBean server.
 * @throws Exception If failed.
 */
private MBeanServer getMBeanServer() throws Exception {
    HttpAdaptor mbeanAdaptor = new HttpAdaptor();

    MBeanServer mbeanSrv = MBeanServerFactory.createMBeanServer();

    mbeanAdaptor.setPort(
        Integer.valueOf(GridTestProperties.getProperty("comm.mbeanserver.selftest.baseport")));

    mbeanSrv.registerMBean(mbeanAdaptor, new ObjectName("mbeanAdaptor:protocol=HTTP"));

    mbeanAdaptor.start();

    return mbeanSrv;
}