当前位置: 首页>>代码示例>>Java>>正文


Java Sender类代码示例

本文整理汇总了Java中io.undertow.io.Sender的典型用法代码示例。如果您正苦于以下问题:Java Sender类的具体用法?Java Sender怎么用?Java Sender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Sender类属于io.undertow.io包,在下文中一共展示了Sender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import io.undertow.io.Sender; //导入依赖的package包/类
/**
 * response
 * 
 * @param exchange
 * @param statusCode
 * @param output
 *            auto release
 */
protected final void send(HttpServerExchange exchange, int statusCode, PooledByteBufferOutputStream output) {
	try {
		output.flip();

		StreamSinkChannel channel = getResponseChannel(exchange);
		Sender sender = exchange.getResponseSender();

		setStatusCode(exchange, statusCode);
		setResponseChannel(sender, channel);
		setPooledBuffers(sender, output.getPooledByteBuffers());

		sender.send(output.getByteBuffers());
	} catch (Throwable t) {
		UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
	}
}
 
开发者ID:hank-whu,项目名称:undertow-async,代码行数:25,代码来源:AsyncHttpHandler.java

示例2: getSender

import io.undertow.io.Sender; //导入依赖的package包/类
@Override
public Sender getSender() {
    try {
        return new BlockingSenderImpl(exchange, getOutputStream());
    } catch (IllegalStateException e) {
        ServletResponse response = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getServletResponse();
        try {
            return new BlockingWriterSenderImpl(exchange, response.getWriter(), response.getCharacterEncoding());
        } catch (IOException e1) {
            throw new RuntimeException(e1);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:ServletBlockingHttpExchange.java

示例3: handleError

import io.undertow.io.Sender; //导入依赖的package包/类
@Override
public void handleError(OvertownRequest request) {
  HttpServerExchange exchange = request.getExchange();
  exchange.setResponseCode(StatusError.METHOD_NOT_ALLOWED.getCode());
  StringBuilder sb = new StringBuilder();
  sb.append("<html>");
  sb.append("<head>");
  sb.append("<title>500 Internal server error</title>");
  sb.append("</head>");
  sb.append("<body>");
  sb.append("<h1>500 Internal server error</h1>");
  sb.append("<p>An unexpected error occurred</p>");
  sb.append("</body>");
  sb.append("</html>");

  Sender rs = exchange.getResponseSender();
  rs.send( sb.toString() );
  rs.close();
}
 
开发者ID:EsmerilProgramming,项目名称:overtown,代码行数:20,代码来源:DefaultInternalErrorPage.java

示例4: handleError

import io.undertow.io.Sender; //导入依赖的package包/类
@Override
public void handleError(OvertownRequest request) {
  HttpServerExchange exchange = request.getExchange();
  exchange.setResponseCode(StatusError.METHOD_NOT_ALLOWED.getCode());
  StringBuilder sb = new StringBuilder();
  sb.append("<html>");
  sb.append("<head>");
  sb.append("<title>405 Method Not Allowed</title>");
  sb.append("</head>");
  sb.append("<body>");
  sb.append("<h1>405 - Method Not Allowed</h1>");
  sb.append("<p>Request method '" + exchange.getRequestMethod().toString().toUpperCase() + "' is not allowed for this path</p>");
  sb.append("</body>");
  sb.append("</html>");

  Sender rs = exchange.getResponseSender();
  rs.send( sb.toString() );
  rs.close();
}
 
开发者ID:EsmerilProgramming,项目名称:overtown,代码行数:20,代码来源:DefaultMethodNotAllowedPage.java

示例5: handleError

import io.undertow.io.Sender; //导入依赖的package包/类
@Override
public void handleError(OvertownRequest request) {
  HttpServerExchange exchange = request.getExchange();Sender rs = exchange.getResponseSender();
  StringBuilder sb = new StringBuilder();
  sb.append("<html>");
  sb.append("<head>");
  sb.append("<title>404 Not Found</title>");
  sb.append("</head>");
  sb.append("<body>");
  sb.append("<h1>404 - Not Found</h1>");
  sb.append("<p>This is not the page you are looking for</p>");
  sb.append("</body>");
  sb.append("</html>");

  exchange.setResponseCode(  StatusError.NOT_FOUND.getCode() );
  rs.send( sb.toString() );
  rs.close();
}
 
开发者ID:EsmerilProgramming,项目名称:overtown,代码行数:19,代码来源:DefaultNotFoundPage.java

示例6: onException

import io.undertow.io.Sender; //导入依赖的package包/类
@Test
public void onException() throws Exception {
  IOException x = new IOException("intentional err");
  new MockUnit(IoCallback.class, HttpServerExchange.class, Sender.class, Logger.class)
      .expect(unit -> {
        unit.mockStatic(LoggerFactory.class);

        Logger log = unit.get(Logger.class);
        log.error("execution of {} resulted in exception", "/assets/main.js", x);

        expect(LoggerFactory.getLogger(NativeResponse.class)).andReturn(log);
        HttpServerExchange exchange = unit.get(HttpServerExchange.class);
        expect(exchange.getRequestPath()).andReturn("/assets/main.js");
        unit.get(IoCallback.class).onException(exchange, unit.get(Sender.class), x);
      })
      .run(unit -> {
        new LogIoCallback(unit.get(IoCallback.class))
            .onException(unit.get(HttpServerExchange.class), unit.get(Sender.class), x);
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:21,代码来源:LogIoCallbackTest.java

示例7: send

import io.undertow.io.Sender; //导入依赖的package包/类
@Test
public void send() throws Exception {
  byte[] bytes = {0};
  CountDownLatch latch = new CountDownLatch(1);
  new MockUnit(HttpServerExchange.class, Sender.class)
    .expect(unit -> {
      Sender sender = unit.get(Sender.class);
      sender.send(eq(ByteBuffer.wrap(bytes)), unit.capture(IoCallback.class));

      HttpServerExchange exchange = unit.get(HttpServerExchange.class);
      expect(exchange.getResponseSender()).andReturn(sender);
    })
    .run(unit -> {
      new UndertowSse(unit.get(HttpServerExchange.class))
        .send(Optional.of("id"), bytes).whenComplete((id, x) -> {
        if (id != null) {
          assertEquals("id", id.get());
          latch.countDown();
        }
      });
    }, unit -> {
      IoCallback callback = unit.captured(IoCallback.class).iterator().next();
      callback.onComplete(unit.get(HttpServerExchange.class), unit.get(Sender.class));
      latch.await();
    });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:27,代码来源:UndertowSseTest.java

示例8: sendNoIoThread2Chunks

import io.undertow.io.Sender; //导入依赖的package包/类
@Test
public void sendNoIoThread2Chunks() throws Exception {
  new MockUnit(ReadableByteChannel.class, HttpServerExchange.class, IoCallback.class,
      Sender.class, PooledByteBuffer.class)
      .expect(exchange)
      .expect(noIoThread)
      .expect(pooled)
      .expect(readLargeChunk)
      .expect(transferEncoding)
      .expect(sendChunk)
      .expect(noIoThread)
      .expect(pooled)
      .expect(readChunk)
      .expect(sendChunk)
      .run(unit -> {
        ChunkedStream chunkedStream = new ChunkedStream();
        chunkedStream.send(unit.get(ReadableByteChannel.class),
            unit.get(HttpServerExchange.class), unit.get(IoCallback.class));
        chunkedStream.onComplete(unit.get(HttpServerExchange.class), unit.get(Sender.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:ChunkedStreamTest.java

示例9: sendNoIoThread2ChunksWithLen

import io.undertow.io.Sender; //导入依赖的package包/类
@Test
public void sendNoIoThread2ChunksWithLen() throws Exception {
  new MockUnit(ReadableByteChannel.class, HttpServerExchange.class, IoCallback.class,
      Sender.class, PooledByteBuffer.class)
      .expect(exchange)
      .expect(noIoThread)
      .expect(pooled)
      .expect(readLargeChunk)
      .expect(len)
      .expect(sendChunk)
      .expect(noIoThread)
      .expect(pooled)
      .expect(readChunk)
      .expect(sendChunk)
      .run(unit -> {
        ChunkedStream chunkedStream = new ChunkedStream();
        chunkedStream.send(unit.get(ReadableByteChannel.class),
            unit.get(HttpServerExchange.class), unit.get(IoCallback.class));
        chunkedStream.onComplete(unit.get(HttpServerExchange.class), unit.get(Sender.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:ChunkedStreamTest.java

示例10: sendIoThread

import io.undertow.io.Sender; //导入依赖的package包/类
@Test
public void sendIoThread() throws Exception {
  new MockUnit(ReadableByteChannel.class, HttpServerExchange.class, IoCallback.class,
      Sender.class, PooledByteBuffer.class)
      .expect(exchange)
      .expect(ioThread)
      .expect(pooled)
      .expect(readChunk)
      .expect(nolen)
      .expect(sendChunk)
      .run(unit -> {
        ChunkedStream chunkedStream = new ChunkedStream();
        chunkedStream.send(unit.get(ReadableByteChannel.class),
            unit.get(HttpServerExchange.class), unit.get(IoCallback.class));
        chunkedStream.run();
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:18,代码来源:ChunkedStreamTest.java

示例11: onComplete

import io.undertow.io.Sender; //导入依赖的package包/类
@Override
public void onComplete(final HttpServerExchange exchange, final Sender sender) {
    try {
        cache.dereference();
    } finally {
        callback.onComplete(exchange, sender);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:CachedResource.java

示例12: onException

import io.undertow.io.Sender; //导入依赖的package包/类
@Override
public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) {
    UndertowLogger.REQUEST_IO_LOGGER.ioException(exception);
    try {
        cache.dereference();
    } finally {
        callback.onException(exchange, sender, exception);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:CachedResource.java

示例13: getResponseSender

import io.undertow.io.Sender; //导入依赖的package包/类
/**
 * Get the response sender.
 * <p/>
 * For blocking exchanges this will return a sender that uses the underlying output stream.
 *
 * @return the response sender, or {@code null} if another party already acquired the channel or the sender
 * @see #getResponseChannel()
 */
public Sender getResponseSender() {
    if (blockingHttpExchange != null) {
        return blockingHttpExchange.getSender();
    }
    if (sender != null) {
        return sender;
    }
    return sender = new AsyncSenderImpl(this);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:HttpServerExchange.java

示例14: getSender

import io.undertow.io.Sender; //导入依赖的package包/类
@Override
public Sender getSender() {
    if (sender == null) {
        sender = new BlockingSenderImpl(exchange, getOutputStream());
    }
    return sender;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:HttpServerExchange.java

示例15: setResponseChannel

import io.undertow.io.Sender; //导入依赖的package包/类
/**
 * force set response channel
 * 
 * @param sender
 * @param channel
 */
private void setResponseChannel(Sender sender, StreamSinkChannel channel) {
	if (!(sender instanceof AsyncSenderImpl)) {
		throw new RuntimeException("only support AsyncSenderImpl");
	}

	unsafe().getAndSetObject(sender, asyncSenderImplChannelFieldOffset, channel);
}
 
开发者ID:hank-whu,项目名称:undertow-async,代码行数:14,代码来源:AsyncHttpHandler.java


注:本文中的io.undertow.io.Sender类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。