use of java.nio.channels.WritableByteChannel in project spring-boot by spring-projects.
the class HttpTunnelPayload method assignTo.
/**
* Assign this payload to the given {@link HttpOutputMessage}.
* @param message the message to assign this payload to
* @throws IOException in case of I/O errors
*/
public void assignTo(HttpOutputMessage message) throws IOException {
Assert.notNull(message, "Message must not be null");
HttpHeaders headers = message.getHeaders();
headers.setContentLength(this.data.remaining());
headers.add(SEQ_HEADER, Long.toString(getSequence()));
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
WritableByteChannel body = Channels.newChannel(message.getBody());
while (this.data.hasRemaining()) {
body.write(this.data);
}
body.close();
}
use of java.nio.channels.WritableByteChannel in project spring-boot by spring-projects.
the class HttpTunnelConnectionTests method closeTunnelChangesIsOpen.
@Test
public void closeTunnelChangesIsOpen() throws Exception {
this.requestFactory.willRespondAfterDelay(1000, HttpStatus.GONE);
WritableByteChannel channel = openTunnel(false);
assertThat(channel.isOpen()).isTrue();
channel.close();
assertThat(channel.isOpen()).isFalse();
}
use of java.nio.channels.WritableByteChannel in project spring-boot by spring-projects.
the class HttpTunnelPayloadForwarderTests method forwardOutOfSequence.
@Test
public void forwardOutOfSequence() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
WritableByteChannel channel = Channels.newChannel(out);
HttpTunnelPayloadForwarder forwarder = new HttpTunnelPayloadForwarder(channel);
forwarder.forward(payload(3, "o"));
forwarder.forward(payload(2, "ll"));
forwarder.forward(payload(1, "he"));
assertThat(out.toByteArray()).isEqualTo("hello".getBytes());
}
use of java.nio.channels.WritableByteChannel in project spring-boot by spring-projects.
the class HttpTunnelPayloadForwarderTests method forwardInSequence.
@Test
public void forwardInSequence() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
WritableByteChannel channel = Channels.newChannel(out);
HttpTunnelPayloadForwarder forwarder = new HttpTunnelPayloadForwarder(channel);
forwarder.forward(payload(1, "he"));
forwarder.forward(payload(2, "ll"));
forwarder.forward(payload(3, "o"));
assertThat(out.toByteArray()).isEqualTo("hello".getBytes());
}
use of java.nio.channels.WritableByteChannel in project spring-boot by spring-projects.
the class HttpTunnelPayloadForwarderTests method overflow.
@Test
public void overflow() throws Exception {
WritableByteChannel channel = Channels.newChannel(new ByteArrayOutputStream());
HttpTunnelPayloadForwarder forwarder = new HttpTunnelPayloadForwarder(channel);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Too many messages queued");
for (int i = 2; i < 130; i++) {
forwarder.forward(payload(i, "data" + i));
}
}
Aggregations