示例#1
0
  /**
   * Create an <code>ObjectName</code> for this <code>Manager</code> object.
   *
   * @param domain Domain in which this name is to be created
   * @param manager The Manager to be named
   * @exception MalformedObjectNameException if a name cannot be created
   */
  static ObjectName createObjectName(String domain, Manager manager)
      throws MalformedObjectNameException {

    ObjectName name = null;
    Container container = manager.getContainer();

    if (container instanceof Engine) {
      name = new ObjectName(domain + ":type=Manager");
    } else if (container instanceof Host) {
      name = new ObjectName(domain + ":type=Manager,host=" + container.getName());
    } else if (container instanceof Context) {
      String path = ((Context) container).getPath();
      if (path.length() < 1) {
        path = "/";
      }
      Host host = (Host) container.getParent();
      name = new ObjectName(domain + ":type=Manager,path=" + path + ",host=" + host.getName());
    } else if (container == null) {
      DefaultContext defaultContext = manager.getDefaultContext();
      if (defaultContext != null) {
        Container parent = defaultContext.getParent();
        if (parent instanceof Engine) {
          name = new ObjectName(domain + ":type=DefaultManager");
        } else if (parent instanceof Host) {
          name = new ObjectName(domain + ":type=DefaultManager,host=" + parent.getName());
        }
      }
    }

    return (name);
  }
示例#2
0
  @Override
  public void finishLocalSetup() {
    final DefaultContext checkContext = new DefaultContext();
    checkContext.add("classLoader", classLoader);
    checkContext.add("messages", getMessageCollector());
    checkContext.add("severity", getSeverity());
    checkContext.add("tabWidth", String.valueOf(tabWidth));

    childContext = checkContext;
  }
示例#3
0
  @Override
  public void finishLocalSetup() {
    final DefaultContext checkContext = new DefaultContext();
    checkContext.add("classLoader", mClassLoader);
    checkContext.add("messages", getMessageCollector());
    checkContext.add("severity", getSeverity());
    // TODO: hmmm.. this looks less than elegant
    // we have just parsed the string,
    // now we're recreating it only to parse it again a few moments later
    checkContext.add("tabWidth", String.valueOf(mTabWidth));

    mChildContext = checkContext;
  }
  @Override
  protected PasswordAuthentication getPasswordAuthentication() {
    DefaultContext dc = DefaultContext.getInstance();
    try (FileInputStream fis = new FileInputStream(dc.getPath() + "/WEB-INF/email.properties"); ) {
      Properties props = new Properties();

      props.load(new BufferedInputStream(fis));

      String id = props.getProperty("id").trim();

      String password = props.getProperty("password").trim();
      return new PasswordAuthentication(id, password);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
示例#5
0
 private void connected(final Channel ch, final Handler<ClientConnection> connectHandler) {
   actualCtx.execute(
       ch.eventLoop(),
       new Runnable() {
         public void run() {
           createConn(ch, connectHandler);
         }
       });
 }
示例#6
0
 @Override
 public void close() {
   checkClosed();
   pool.close();
   for (ClientConnection conn : connectionMap.values()) {
     conn.close();
   }
   actualCtx.removeCloseHook(closeHook);
   closed = true;
 }
示例#7
0
  /**
   * Create an <code>ObjectName</code> for this <code>DefaultContext</code> object.
   *
   * @param domain Domain in which this name is to be created
   * @param context The DefaultContext to be named
   * @exception MalformedObjectNameException if a name cannot be created
   */
  static ObjectName createObjectName(String domain, DefaultContext context)
      throws MalformedObjectNameException {

    ObjectName name = null;
    Container container = context.getParent();
    if (container instanceof Host) {
      Host host = (Host) container;
      name = new ObjectName(domain + ":type=DefaultContext,host=" + host.getName());
    } else if (container instanceof Engine) {
      name = new ObjectName(domain + ":type=DefaultContext");
    }

    return (name);
  }
示例#8
0
  private void failed(
      final Channel ch, final Handler<Throwable> connectionExceptionHandler, final Throwable t) {
    // If no specific exception handler is provided, fall back to the HttpClient's exception
    // handler.
    final Handler<Throwable> exHandler =
        connectionExceptionHandler == null ? exceptionHandler : connectionExceptionHandler;

    actualCtx.execute(
        ch.eventLoop(),
        new Runnable() {
          public void run() {
            pool.connectionClosed();
            try {
              ch.close();
            } catch (Exception ignore) {
            }
            if (exHandler != null) {
              exHandler.handle(t);
            } else {
              actualCtx.reportException(t);
            }
          }
        });
  }
示例#9
0
 /** {@inheritDoc} */
 @Override
 public final void apply(final Object context, final Writer writer) throws IOException {
   checkNotNull(writer, "A writer is required.");
   merge(DefaultContext.wrap(context), writer);
 }
示例#10
0
 public DefaultHttpClient(VertxInternal vertx) {
   this.vertx = vertx;
   actualCtx = vertx.getOrCreateContext();
   actualCtx.addCloseHook(closeHook);
 }
示例#11
0
  void internalConnect(
      final Handler<ClientConnection> connectHandler,
      final Handler<Throwable> connectErrorHandler) {

    if (bootstrap == null) {
      // Share the event loop thread to also serve the HttpClient's network traffic.
      VertxEventLoopGroup pool = new VertxEventLoopGroup();
      pool.addWorker(actualCtx.getEventLoop());
      bootstrap = new Bootstrap();
      bootstrap.group(pool);
      bootstrap.channel(NioSocketChannel.class);
      tcpHelper.checkSSL(vertx);

      bootstrap.handler(
          new ChannelInitializer<Channel>() {
            @Override
            protected void initChannel(Channel ch) throws Exception {
              ChannelPipeline pipeline = ch.pipeline();
              pipeline.addLast("exceptionDispatcher", EXCEPTION_DISPATCH_HANDLER);

              if (tcpHelper.isSSL()) {
                SSLEngine engine = tcpHelper.getSSLContext().createSSLEngine(host, port);
                if (tcpHelper.isVerifyHost()) {
                  SSLParameters sslParameters = engine.getSSLParameters();
                  sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
                  engine.setSSLParameters(sslParameters);
                }
                engine.setUseClientMode(true); // We are on the client side of the connection
                pipeline.addLast("ssl", new SslHandler(engine));
              }

              pipeline.addLast("codec", new HttpClientCodec());
              pipeline.addLast("handler", new ClientHandler());
            }
          });
    }
    tcpHelper.applyConnectionOptions(bootstrap);
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
    future.addListener(
        new ChannelFutureListener() {
          public void operationComplete(ChannelFuture channelFuture) throws Exception {
            final Channel ch = channelFuture.channel();
            if (channelFuture.isSuccess()) {
              if (tcpHelper.isSSL()) {
                // TCP connected, so now we must do the SSL handshake

                SslHandler sslHandler = ch.pipeline().get(SslHandler.class);

                Future<Channel> fut = sslHandler.handshakeFuture();
                fut.addListener(
                    new GenericFutureListener<Future<Channel>>() {
                      @Override
                      public void operationComplete(Future<Channel> future) throws Exception {
                        if (future.isSuccess()) {
                          connected(ch, connectHandler);
                        } else {
                          failed(
                              ch,
                              connectErrorHandler,
                              new SSLHandshakeException("Failed to create SSL connection"));
                        }
                      }
                    });
              } else {
                connected(ch, connectHandler);
              }
            } else {
              failed(ch, connectErrorHandler, channelFuture.cause());
            }
          }
        });
  }
 private void assertDefaultContext(DefaultContext dc) {
   Assert.assertNotNull(dc);
   assertContextProperty((ContextProperty) dc.getProperties().iterator().next());
 }