use of org.eclipse.jetty.http2.parser.Parser in project jetty.project by eclipse.
the class SettingsGenerateParseTest method testGenerateParseInvalidSettings.
@Test
public void testGenerateParseInvalidSettings() throws Exception {
SettingsGenerator generator = new SettingsGenerator(new HeaderGenerator());
final AtomicInteger errorRef = new AtomicInteger();
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {
@Override
public void onConnectionFailure(int error, String reason) {
errorRef.set(error);
}
}, 4096, 8192);
Map<Integer, Integer> settings1 = new HashMap<>();
settings1.put(13, 17);
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.generateSettings(lease, settings1, true);
// Modify the length of the frame to make it invalid
ByteBuffer bytes = lease.getByteBuffers().get(0);
bytes.putShort(1, (short) (bytes.getShort(1) - 1));
for (ByteBuffer buffer : lease.getByteBuffers()) {
while (buffer.hasRemaining()) {
parser.parse(ByteBuffer.wrap(new byte[] { buffer.get() }));
}
}
Assert.assertEquals(ErrorCode.FRAME_SIZE_ERROR.code, errorRef.get());
}
use of org.eclipse.jetty.http2.parser.Parser in project jetty.project by eclipse.
the class SettingsGenerateParseTest method testGenerateParseOneByteAtATime.
@Test
public void testGenerateParseOneByteAtATime() throws Exception {
SettingsGenerator generator = new SettingsGenerator(new HeaderGenerator());
final List<SettingsFrame> frames = new ArrayList<>();
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {
@Override
public void onSettings(SettingsFrame frame) {
frames.add(frame);
}
}, 4096, 8192);
Map<Integer, Integer> settings1 = new HashMap<>();
int key = 13;
Integer value = 17;
settings1.put(key, value);
// Iterate a few times to be sure generator and parser are properly reset.
for (int i = 0; i < 2; ++i) {
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.generateSettings(lease, settings1, true);
frames.clear();
for (ByteBuffer buffer : lease.getByteBuffers()) {
while (buffer.hasRemaining()) {
parser.parse(ByteBuffer.wrap(new byte[] { buffer.get() }));
}
}
Assert.assertEquals(1, frames.size());
SettingsFrame frame = frames.get(0);
Map<Integer, Integer> settings2 = frame.getSettings();
Assert.assertEquals(1, settings2.size());
Assert.assertEquals(value, settings2.get(key));
Assert.assertTrue(frame.isReply());
}
}
use of org.eclipse.jetty.http2.parser.Parser in project jetty.project by eclipse.
the class SettingsGenerateParseTest method testGenerateParse.
private List<SettingsFrame> testGenerateParse(Map<Integer, Integer> settings) {
SettingsGenerator generator = new SettingsGenerator(new HeaderGenerator());
final List<SettingsFrame> frames = new ArrayList<>();
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {
@Override
public void onSettings(SettingsFrame frame) {
frames.add(frame);
}
}, 4096, 8192);
// Iterate a few times to be sure generator and parser are properly reset.
for (int i = 0; i < 2; ++i) {
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.generateSettings(lease, settings, true);
frames.clear();
for (ByteBuffer buffer : lease.getByteBuffers()) {
while (buffer.hasRemaining()) {
parser.parse(buffer);
}
}
}
return frames;
}
use of org.eclipse.jetty.http2.parser.Parser in project jetty.project by eclipse.
the class SettingsBodyParser method parseBody.
public static SettingsFrame parseBody(final ByteBuffer buffer) {
final int bodyLength = buffer.remaining();
final AtomicReference<SettingsFrame> frameRef = new AtomicReference<>();
SettingsBodyParser parser = new SettingsBodyParser(null, null) {
@Override
protected int getStreamId() {
return 0;
}
@Override
protected int getBodyLength() {
return bodyLength;
}
@Override
protected boolean onSettings(Map<Integer, Integer> settings) {
frameRef.set(new SettingsFrame(settings, false));
return true;
}
@Override
protected boolean connectionFailure(ByteBuffer buffer, int error, String reason) {
frameRef.set(null);
return false;
}
};
if (bodyLength == 0)
parser.emptyBody(buffer);
else
parser.parse(buffer);
return frameRef.get();
}
use of org.eclipse.jetty.http2.parser.Parser in project camel by apache.
the class HL7ValidateTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
HapiContext hapiContext = new DefaultHapiContext();
hapiContext.setValidationContext(new NoValidation());
Parser p = new GenericParser(hapiContext);
hl7 = new HL7DataFormat();
hl7.setParser(p);
/*
* Let's start by adding a validation rule to the default validation
* that disallows PID-2 to be empty.
*/
ValidationRuleBuilder builder = new ValidationRuleBuilder() {
private static final long serialVersionUID = 1L;
@Override
protected void configure() {
forVersion(Version.V24).message("ADT", "*").terser("PID-2", not(empty()));
}
};
ValidationContext customValidationContext = ValidationContextFactory.fromBuilder(builder);
HapiContext customContext = new DefaultHapiContext(customValidationContext);
final Parser customParser = new GenericParser(customContext);
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:unmarshalFailed").unmarshal().hl7().to("mock:unmarshal");
from("direct:unmarshalOk").unmarshal().hl7(false).to("mock:unmarshal");
from("direct:unmarshalOkCustom").unmarshal(hl7).to("mock:unmarshal");
from("direct:start1").marshal().hl7(customParser).to("mock:end");
from("direct:start2").marshal().hl7(true).to("mock:end");
}
};
}
Aggregations