/**
   * Dummy Main method
   *
   * @param args
   */
  public static void main(String[] args) {
    InternalLoggerFactory.setDefaultFactory(new WaarpSlf4JLoggerFactory(null));
    if (logger == null) {
      logger = WaarpInternalLoggerFactory.getLogger(AbstractBusinessRequest.class);
    }
    if (!getParams(args)) {
      logger.error("Wrong initialization");
      if (DbConstant.admin != null && DbConstant.admin.isConnected) {
        DbConstant.admin.close();
      }
      ChannelUtils.stopLogger();
      System.exit(2);
    }

    Configuration.configuration.pipelineInit();
    NetworkTransaction networkTransaction = new NetworkTransaction();
    R66Future future = new R66Future(true);

    logger.info("Start Test of Transaction");
    long time1 = System.currentTimeMillis();

    @SuppressWarnings("unused")
    BusinessRequestPacket packet = new BusinessRequestPacket(classname + " " + classarg, 0);
    // XXX FIXME this has to be adapted
    /*
     * AbstractBusinessRequest transaction = new AbstractBusinessRequest(
     * AbstractBusinessRequest.class, future, rhost, networkTransaction, packet);
     * transaction.run(); future.awaitUninterruptibly();
     */
    long time2 = System.currentTimeMillis();
    logger.debug("Finish Business Request: " + future.isSuccess());
    long delay = time2 - time1;
    if (future.isSuccess()) {
      logger.info(
          "Business Request in status:\nSUCCESS"
              + "\n    <REMOTE>"
              + rhost
              + "</REMOTE>"
              + "\n    delay: "
              + delay);
    } else {
      logger.info(
          "Business Request in status:\nFAILURE"
              + "\n    <REMOTE>"
              + rhost
              + "</REMOTE>"
              + "\n    <ERROR>"
              + future.getCause()
              + "</ERROR>"
              + "\n    delay: "
              + delay);
      networkTransaction.closeAll();
      System.exit(ErrorCode.Unknown.ordinal());
    }
    networkTransaction.closeAll();
  }
 public void sendRequest() {
   try {
     ChannelUtils.writeAbstractLocalPacket(localChannelReference, businessPacket, false);
   } catch (OpenR66ProtocolPacketException e) {
     future.setResult(null);
     future.setFailure(e);
     Channels.close(localChannelReference.getLocalChannel());
     return;
   }
 }
Пример #3
0
  /** Write the response */
  private void writeResponse(ChannelHandlerContext ctx) {
    // Convert the response content to a ByteBuf.
    ByteBuf buf = Unpooled.copiedBuffer(responseContent.toString(), WaarpStringUtils.UTF8);
    responseContent.setLength(0);

    // Decide whether to close the connection or not.
    boolean keepAlive = HttpUtil.isKeepAlive(request);
    boolean close =
        HttpHeaderValues.CLOSE.contentEqualsIgnoreCase(
                request.headers().get(HttpHeaderNames.CONNECTION))
            || (!keepAlive)
            || forceClose;

    // Build the response object.
    FullHttpResponse response =
        new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf);
    response.headers().add(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
    response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html");
    if (keepAlive) {
      response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    }
    if (!close) {
      // There's no need to add 'Content-Length' header
      // if this is the last response.
      response.headers().set(HttpHeaderNames.CONTENT_LENGTH, String.valueOf(buf.readableBytes()));
    }

    handleCookies(response);

    // Write the response.
    ChannelFuture future = ctx.writeAndFlush(response);
    // Close the connection after the write operation is done if necessary.
    if (close) {
      future.addListener(WaarpSslUtility.SSLCLOSE);
    }
    if (shutdown) {
      ChannelUtils.startShutdown();
    }
  }