Search in sources :

Example 11 with RequestMessage

use of org.neo4j.bolt.messaging.RequestMessage in project neo4j by neo4j.

the class BoltProtocolV4ComponentFactory method encode.

public static byte[] encode(Neo4jPack neo4jPack, RequestMessage... messages) throws IOException {
    RecordingByteChannel rawData = new RecordingByteChannel();
    Neo4jPack.Packer packer = neo4jPack.newPacker(new BufferedChannelOutput(rawData));
    BoltRequestMessageWriter writer = requestMessageWriter(packer);
    for (RequestMessage message : messages) {
        writer.write(message);
    }
    writer.flush();
    return rawData.getBytes();
}
Also used : RequestMessage(org.neo4j.bolt.messaging.RequestMessage) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) BoltRequestMessageWriter(org.neo4j.bolt.messaging.BoltRequestMessageWriter) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput)

Example 12 with RequestMessage

use of org.neo4j.bolt.messaging.RequestMessage in project neo4j by neo4j.

the class BoltProtocolV3ComponentFactory method encode.

public static byte[] encode(Neo4jPack neo4jPack, RequestMessage... messages) throws IOException {
    RecordingByteChannel rawData = new RecordingByteChannel();
    Neo4jPack.Packer packer = neo4jPack.newPacker(new BufferedChannelOutput(rawData));
    BoltRequestMessageWriter writer = requestMessageWriter(packer);
    for (RequestMessage message : messages) {
        writer.write(message);
    }
    writer.flush();
    return rawData.getBytes();
}
Also used : RequestMessage(org.neo4j.bolt.messaging.RequestMessage) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) BoltRequestMessageWriter(org.neo4j.bolt.messaging.BoltRequestMessageWriter) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput)

Example 13 with RequestMessage

use of org.neo4j.bolt.messaging.RequestMessage in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeWhenEmptyRoutingContextProvided.

@Test
void testShouldDecodeWhenEmptyRoutingContextProvided() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Map<String, String> parameterMap = new HashMap<>();
    RoutingContext routingContext = new RoutingContext(true, parameterMap);
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", parameterMap);
    HelloMessage originalMessage = new HelloMessage(meta, routingContext, meta);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    // these two steps are executed before decoding in order to select a correct decoder
    unpacker.unpackStructHeader();
    unpacker.unpackStructSignature();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertHelloMessageMatches(originalMessage, deserializedMessage);
    assertRoutingContextMatches(originalMessage, deserializedMessage);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack) AuthTokenDecoderTest(org.neo4j.bolt.security.auth.AuthTokenDecoderTest) Test(org.junit.jupiter.api.Test)

Example 14 with RequestMessage

use of org.neo4j.bolt.messaging.RequestMessage in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeRoutingContext.

@Test
void testShouldDecodeRoutingContext() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Map<String, Object> authToken;
    Map<String, String> parameterMap = new HashMap<>();
    RoutingContext routingContext = new RoutingContext(true, parameterMap);
    parameterMap.put("policy", "fast");
    parameterMap.put("region", "eu-west");
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", parameterMap);
    authToken = new HashMap<>(Map.copyOf(meta));
    authToken.remove("routing");
    HelloMessage originalMessage = new HelloMessage(meta, routingContext, authToken);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    // these two steps are executed before decoding in order to select a correct decoder
    unpacker.unpackStructHeader();
    unpacker.unpackStructSignature();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertHelloMessageMatches(originalMessage, deserializedMessage);
    assertRoutingContextMatches(originalMessage, deserializedMessage);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack) AuthTokenDecoderTest(org.neo4j.bolt.security.auth.AuthTokenDecoderTest) Test(org.junit.jupiter.api.Test)

Example 15 with RequestMessage

use of org.neo4j.bolt.messaging.RequestMessage in project neo4j by neo4j.

the class PullMessageDecoderTest method assertOriginalMessageEqualsToDecoded.

private static void assertOriginalMessageEqualsToDecoded(RequestMessage originalMessage, RequestMessageDecoder decoder) throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    // these two steps are executed before decoding in order to select a correct decoder
    unpacker.unpackStructHeader();
    unpacker.unpackStructSignature();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertEquals(originalMessage, deserializedMessage);
}
Also used : RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) BoltProtocolV4ComponentFactory.newNeo4jPack(org.neo4j.bolt.v4.BoltProtocolV4ComponentFactory.newNeo4jPack) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack)

Aggregations

RequestMessage (org.neo4j.bolt.messaging.RequestMessage)17 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)15 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)10 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)8 BoltRequestMessageWriter (org.neo4j.bolt.messaging.BoltRequestMessageWriter)6 RecordingByteChannel (org.neo4j.bolt.messaging.RecordingByteChannel)6 BufferedChannelOutput (org.neo4j.bolt.packstream.BufferedChannelOutput)6 Test (org.junit.jupiter.api.Test)5 RoutingContext (org.neo4j.bolt.v41.messaging.RoutingContext)4 HelloMessage (org.neo4j.bolt.v41.messaging.request.HelloMessage)4 HashMap (java.util.HashMap)3 AuthTokenDecoderTest (org.neo4j.bolt.security.auth.AuthTokenDecoderTest)3 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)2 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)2 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)2 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)2 NullLogService (org.neo4j.logging.internal.NullLogService)2 ByteBuf (io.netty.buffer.ByteBuf)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 IOException (java.io.IOException)1