Search in sources :

Example 1 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class MessageConditions method serialize.

public static byte[] serialize(Neo4jPack neo4jPack, RequestMessage... messages) throws IOException {
    RecordingByteChannel rawData = new RecordingByteChannel();
    Neo4jPack.Packer packer = neo4jPack.newPacker(new BufferedChannelOutput(rawData));
    BoltRequestMessageWriter writer = new BoltRequestMessageWriterV4(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) BoltRequestMessageWriterV4(org.neo4j.bolt.v4.BoltRequestMessageWriterV4) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput)

Example 2 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeAuthToken.

@Override
protected void testShouldDecodeAuthToken(Map<String, Object> authToken) throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    authToken.put("user_agent", "My Driver");
    HelloMessage originalMessage = new HelloMessage(authToken, new RoutingContext(true, Collections.emptyMap()), 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);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) 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)

Example 3 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class HelloMessageDecoderTest method shouldThrowExceptionOnIncorrectRoutingContextFormat.

@Test
public void shouldThrowExceptionOnIncorrectRoutingContextFormat() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    // incorrect Map type params
    Map<String, Integer> routingContext = new HashMap<>();
    routingContext.put("policy", 4);
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", routingContext);
    HelloMessage originalMessage = new HelloMessage(meta, null, 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();
    BoltIOException ex = assertThrows(BoltIOException.class, () -> decoder.decode(unpacker));
    assertEquals("Routing information in the HELLO message must be a map with string keys and string values.", ex.getMessage());
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) 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 4 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class HelloMessageDecoderTest method assertOriginalMessageEqualsToDecoded.

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);
    assertAuthTokenDoesNotContainRoutingContext(deserializedMessage);
}
Also used : 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)

Example 5 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeWhenNoRoutingContextProvided.

@Test
void testShouldDecodeWhenNoRoutingContextProvided() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    HelloMessage originalMessage = new HelloMessage(meta, new RoutingContext(false, Collections.emptyMap()), 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)

Aggregations

Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)26 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)18 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)14 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)10 BoltRequestMessageReader (org.neo4j.bolt.messaging.BoltRequestMessageReader)7 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)7 HashMap (java.util.HashMap)5 Test (org.junit.jupiter.api.Test)5 BoltRequestMessageWriter (org.neo4j.bolt.messaging.BoltRequestMessageWriter)5 RecordingByteChannel (org.neo4j.bolt.messaging.RecordingByteChannel)5 BufferedChannelOutput (org.neo4j.bolt.packstream.BufferedChannelOutput)5 AuthTokenDecoderTest (org.neo4j.bolt.security.auth.AuthTokenDecoderTest)5 HelloMessage (org.neo4j.bolt.v41.messaging.request.HelloMessage)5 BoltProtocolV4ComponentFactory.newNeo4jPack (org.neo4j.bolt.v4.BoltProtocolV4ComponentFactory.newNeo4jPack)4 RoutingContext (org.neo4j.bolt.v41.messaging.RoutingContext)4 PackedOutputArray (org.neo4j.bolt.packstream.PackedOutputArray)3 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)2 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)2 BoltProtocolV41ComponentFactory.newNeo4jPack (org.neo4j.bolt.v41.BoltProtocolV41ComponentFactory.newNeo4jPack)2 BoltProtocolV43ComponentFactory.newNeo4jPack (org.neo4j.bolt.v43.BoltProtocolV43ComponentFactory.newNeo4jPack)2