Search in sources :

Example 1 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext in project neo4j by neo4j.

the class ConnectedState method process.

@Override
public BoltStateMachineState process(RequestMessage message, StateMachineContext context) throws BoltConnectionFatality {
    assertInitialized();
    if (message instanceof HelloMessage) {
        HelloMessage helloMessage = (HelloMessage) message;
        String userAgent = helloMessage.userAgent();
        Map<String, Object> authToken = helloMessage.authToken();
        if (processAuthentication(userAgent, authToken, context, new RoutingContext(false, Collections.emptyMap()))) {
            context.resolveDefaultDatabase();
            context.connectionState().onMetadata(CONNECTION_ID_KEY, Values.utf8Value(context.connectionId()));
            context.connectionState().onMetadata("hints", connectionHints);
            return readyState;
        } else {
            return null;
        }
    }
    return null;
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v3.messaging.request.HelloMessage)

Example 2 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext in project neo4j by neo4j.

the class TestFabricGraphDatabaseService method beginTransactionInternal.

@Override
protected InternalTransaction beginTransactionInternal(KernelTransaction.Type type, LoginContext loginContext, ClientConnectionInfo connectionInfo, long timeoutMillis, Consumer<Status> terminationCallback, TransactionExceptionMapper transactionExceptionMapper) {
    var databaseService = boltFabricDatabaseServiceSupplier.get();
    var boltTransaction = databaseService.beginTransaction(type, loginContext, connectionInfo, List.of(), Duration.ofMillis(timeoutMillis), AccessMode.WRITE, Map.of(), new RoutingContext(false, Map.of()));
    var internalTransaction = forceKernelTxCreation(boltTransaction);
    return new TestFabricTransaction(boltTransaction, internalTransaction);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext)

Example 3 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext in project neo4j by neo4j.

the class FabricExecutor method run.

public StatementResult run(FabricTransaction fabricTransaction, String statement, MapValue parameters) {
    StatementLifecycle lifecycle = statementLifecycles.create(fabricTransaction.getTransactionInfo(), statement, parameters);
    lifecycle.startProcessing();
    fabricTransaction.setLastSubmittedStatement(lifecycle);
    try {
        String defaultGraphName = fabricTransaction.getTransactionInfo().getSessionDatabaseId().name();
        FabricPlanner.PlannerInstance plannerInstance = planner.instance(statement, parameters, defaultGraphName);
        UseEvaluation.Instance useEvaluator = useEvaluation.instance(statement);
        FabricPlan plan = plannerInstance.plan();
        Fragment query = plan.query();
        lifecycle.doneFabricProcessing(plan);
        AccessMode accessMode = fabricTransaction.getTransactionInfo().getAccessMode();
        RoutingContext routingContext = fabricTransaction.getTransactionInfo().getRoutingContext();
        if (plan.debugOptions().logPlan()) {
            log.debug(String.format("Fabric plan: %s", Fragment.pretty().asString(query)));
        }
        var statementResult = fabricTransaction.execute(ctx -> {
            FabricStatementExecution execution;
            if (plan.debugOptions().logRecords()) {
                execution = new FabricLoggingStatementExecution(plan, plannerInstance, useEvaluator, parameters, accessMode, routingContext, ctx, log, lifecycle, dataStreamConfig);
            } else {
                execution = new FabricStatementExecution(plan, plannerInstance, useEvaluator, parameters, accessMode, routingContext, ctx, lifecycle, dataStreamConfig);
            }
            return execution.run();
        });
        var resultWithErrorMapping = withErrorMapping(statementResult, FabricSecondaryException.class, FabricSecondaryException::getPrimaryException);
        return new FabricExecutionStatementResultImpl(resultWithErrorMapping, failure -> rollbackOnFailure(fabricTransaction, failure));
    } catch (RuntimeException e) {
        lifecycle.endFailure(e);
        rollbackOnFailure(fabricTransaction, e);
        throw e;
    }
}
Also used : UseEvaluation(org.neo4j.fabric.eval.UseEvaluation) FabricPlan(org.neo4j.fabric.planning.FabricPlan) Fragment(org.neo4j.fabric.planning.Fragment) RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) StatementLifecycle(org.neo4j.fabric.executor.FabricStatementLifecycles.StatementLifecycle) AccessMode(org.neo4j.bolt.runtime.AccessMode) FabricPlanner(org.neo4j.fabric.planning.FabricPlanner)

Example 4 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext 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 5 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext 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)

Aggregations

RoutingContext (org.neo4j.bolt.v41.messaging.RoutingContext)12 HelloMessage (org.neo4j.bolt.v41.messaging.request.HelloMessage)9 Test (org.junit.jupiter.api.Test)7 AuthTokenDecoderTest (org.neo4j.bolt.security.auth.AuthTokenDecoderTest)6 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)5 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)5 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)5 HashMap (java.util.HashMap)4 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)4 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)1 AccessMode (org.neo4j.bolt.runtime.AccessMode)1 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)1 UseEvaluation (org.neo4j.fabric.eval.UseEvaluation)1 StatementLifecycle (org.neo4j.fabric.executor.FabricStatementLifecycles.StatementLifecycle)1 FabricPlan (org.neo4j.fabric.planning.FabricPlan)1 FabricPlanner (org.neo4j.fabric.planning.FabricPlanner)1 Fragment (org.neo4j.fabric.planning.Fragment)1 FabricTransactionInfo (org.neo4j.fabric.transaction.FabricTransactionInfo)1