use of org.eclipse.jetty.websocket.api.extensions.Extension in project jetty.project by eclipse.
the class IdentityExtensionTest method testOutgoingFrames.
/**
* Verify that outgoing frames are unmodified
* @throws IOException on test failure
*/
@Test
public void testOutgoingFrames() throws IOException {
OutgoingFramesCapture capture = new OutgoingFramesCapture();
Extension ext = new IdentityExtension();
ext.setNextOutgoingFrames(capture);
Frame frame = new TextFrame().setPayload("hello");
ext.outgoingFrame(frame, null, BatchMode.OFF);
capture.assertFrameCount(1);
capture.assertHasFrame(OpCode.TEXT, 1);
WebSocketFrame actual = capture.getFrames().getFirst();
Assert.assertThat("Frame.opcode", actual.getOpCode(), is(OpCode.TEXT));
Assert.assertThat("Frame.fin", actual.isFin(), is(true));
Assert.assertThat("Frame.rsv1", actual.isRsv1(), is(false));
Assert.assertThat("Frame.rsv2", actual.isRsv2(), is(false));
Assert.assertThat("Frame.rsv3", actual.isRsv3(), is(false));
ByteBuffer expected = BufferUtil.toBuffer("hello", StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength", actual.getPayloadLength(), is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload", expected, actual.getPayload().slice());
}
use of org.eclipse.jetty.websocket.api.extensions.Extension in project jetty.project by eclipse.
the class ExtensionStack method negotiate.
/**
* Perform the extension negotiation.
* <p>
* For the list of negotiated extensions, use {@link #getNegotiatedExtensions()}
*
* @param configs
* the configurations being requested
*/
public void negotiate(List<ExtensionConfig> configs) {
if (LOG.isDebugEnabled())
LOG.debug("Extension Configs={}", configs);
this.extensions = new ArrayList<>();
String[] rsvClaims = new String[3];
for (ExtensionConfig config : configs) {
Extension ext = factory.newInstance(config);
if (ext == null) {
// Extension not present on this side
continue;
}
// Check RSV
if (ext.isRsv1User() && (rsvClaims[0] != null)) {
LOG.debug("Not adding extension {}. Extension {} already claimed RSV1", config, rsvClaims[0]);
continue;
}
if (ext.isRsv2User() && (rsvClaims[1] != null)) {
LOG.debug("Not adding extension {}. Extension {} already claimed RSV2", config, rsvClaims[1]);
continue;
}
if (ext.isRsv3User() && (rsvClaims[2] != null)) {
LOG.debug("Not adding extension {}. Extension {} already claimed RSV3", config, rsvClaims[2]);
continue;
}
// Add Extension
extensions.add(ext);
addBean(ext);
if (LOG.isDebugEnabled())
LOG.debug("Adding Extension: {}", config);
// Record RSV Claims
if (ext.isRsv1User()) {
rsvClaims[0] = ext.getName();
}
if (ext.isRsv2User()) {
rsvClaims[1] = ext.getName();
}
if (ext.isRsv3User()) {
rsvClaims[2] = ext.getName();
}
}
}
use of org.eclipse.jetty.websocket.api.extensions.Extension in project jetty.project by eclipse.
the class WebSocketExtensionFactory method newInstance.
@Override
public Extension newInstance(ExtensionConfig config) {
if (config == null) {
return null;
}
String name = config.getName();
if (StringUtil.isBlank(name)) {
return null;
}
Class<? extends Extension> extClass = getExtension(name);
if (extClass == null) {
return null;
}
try {
Extension ext = container.getObjectFactory().createInstance(extClass);
if (ext instanceof AbstractExtension) {
AbstractExtension aext = (AbstractExtension) ext;
aext.init(container);
aext.setConfig(config);
}
return ext;
} catch (InstantiationException | IllegalAccessException e) {
throw new WebSocketException("Cannot instantiate extension: " + extClass, e);
}
}
use of org.eclipse.jetty.websocket.api.extensions.Extension in project jetty.project by eclipse.
the class ExtensionStack method toString.
@Override
public String toString() {
StringBuilder s = new StringBuilder();
s.append("ExtensionStack[");
s.append("queueSize=").append(getQueueSize());
s.append(",extensions=");
if (extensions == null) {
s.append("<null>");
} else {
s.append('[');
boolean delim = false;
for (Extension ext : extensions) {
if (delim) {
s.append(',');
}
if (ext == null) {
s.append("<null>");
} else {
s.append(ext.getName());
}
delim = true;
}
s.append(']');
}
s.append(",incoming=").append((this.nextIncoming == null) ? "<null>" : this.nextIncoming.getClass().getName());
s.append(",outgoing=").append((this.nextOutgoing == null) ? "<null>" : this.nextOutgoing.getClass().getName());
s.append("]");
return s.toString();
}
use of org.eclipse.jetty.websocket.api.extensions.Extension in project jetty.project by eclipse.
the class ExtensionStack method dump.
@Override
public void dump(Appendable out, String indent) throws IOException {
super.dump(out, indent);
IncomingFrames websocket = getLastIncoming();
OutgoingFrames network = getLastOutgoing();
out.append(indent).append(" +- Stack").append(System.lineSeparator());
out.append(indent).append(" +- Network : ").append(network.toString()).append(System.lineSeparator());
for (Extension ext : extensions) {
out.append(indent).append(" +- Extension: ").append(ext.toString()).append(System.lineSeparator());
}
out.append(indent).append(" +- Websocket: ").append(websocket.toString()).append(System.lineSeparator());
}
Aggregations