本文整理汇总了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);
}
}
示例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);
}
}
}
示例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();
}
示例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();
}
示例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();
}
示例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);
});
}
示例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();
});
}
示例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));
});
}
示例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));
});
}
示例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();
});
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例14: getSender
import io.undertow.io.Sender; //导入依赖的package包/类
@Override
public Sender getSender() {
if (sender == null) {
sender = new BlockingSenderImpl(exchange, getOutputStream());
}
return sender;
}
示例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);
}