return Status.Transaction.valueOf( error ); case "Request": return Status.Request.valueOf( error ); case "Network": return Status.Network.valueOf( error );
@Override public void handleSchedulingError( Throwable t ) { // if the connection is closing, don't output any logs if ( !willClose() ) { String message; Neo4jError error; if ( ExceptionUtils.hasCause( t, RejectedExecutionException.class ) ) { error = Neo4jError.from( Status.Request.NoThreadsAvailable, Status.Request.NoThreadsAvailable.code().description() ); message = String.format( "Unable to schedule bolt session '%s' for execution since there are no available threads to " + "serve it at the moment. You can retry at a later time or consider increasing max thread pool size for bolt connector(s).", id() ); } else { error = Neo4jError.fatalFrom( t ); message = String.format( "Unexpected error during scheduling of bolt session '%s'.", id() ); } log.error( message, t ); userLog.error( message ); machine.markFailed( error ); } // this will ensure that the scheduled job will be executed on this thread (fork-join pool) // and it will either send a failure response to the client or close the connection and its // related resources (if closing) processNextBatch( 1, true ); }
return Status.Transaction.valueOf( error ); case "Request": return Status.Request.valueOf( error ); case "Network": return Status.Network.valueOf( error );
public static Status codeFromString( String codeStr ) { String[] parts = codeStr.split( "\\." ); if ( parts.length != 4 ) { return Status.General.UnknownFailure; } String category = parts[2]; String error = parts[3]; // Note: the input string may contain arbitrary input data, using reflection would open network attack vector switch ( category ) { case "Schema": return Status.Schema.valueOf( error ); case "LegacyIndex": return Status.LegacyIndex.valueOf( error ); case "General": return Status.General.valueOf( error ); case "Statement": return Status.Statement.valueOf( error ); case "Transaction": return Status.Transaction.valueOf( error ); case "Request": return Status.Request.valueOf( error ); case "Network": return Status.Network.valueOf( error ); default: return Status.General.UnknownFailure; } }
return Status.Transaction.valueOf( error ); case "Request": return Status.Request.valueOf( error ); case "Network": return Status.Network.valueOf( error );
@Override public void handleSchedulingError( Throwable t ) { // if the connection is closing, don't output any logs if ( !willClose() ) { String message; Neo4jError error; if ( ExceptionUtils.hasCause( t, RejectedExecutionException.class ) ) { error = Neo4jError.from( Status.Request.NoThreadsAvailable, Status.Request.NoThreadsAvailable.code().description() ); message = String.format( "Unable to schedule bolt session '%s' for execution since there are no available threads to " + "serve it at the moment. You can retry at a later time or consider increasing max thread pool size for bolt connector(s).", id() ); } else { error = Neo4jError.fatalFrom( t ); message = String.format( "Unexpected error during scheduling of bolt session '%s'.", id() ); } log.error( message, t ); userLog.error( message ); machine.markFailed( error ); } // this will ensure that the scheduled job will be executed on this thread (fork-join pool) // and it will either send a failure response to the client or close the connection and its // related resources (if closing) processNextBatch( 1, true ); }
@Test public void shouldRespondWith400WhenSettingRelationshipPropertiesWithBadJson() throws Exception { long relationshipId = helper.createRelationship( "KNOWS" ); String json = "{\"name: \"Mattias\", \"age\": 30}"; Response response = service.setAllRelationshipProperties( relationshipId, json ); assertEquals( 400, response.getStatus() ); assertEquals( Request.InvalidFormat.code().serialize(), singleErrorCode( response ) ); }
@Test public void shouldRespondWith400WhenTryingToCreateRelationshipWithBadJson() throws Exception { long startNode = helper.createNode(); long endNode = helper.createNode(); Response response = service.createRelationship( startNode, "{\"to\" : \"" + BASE_URI + endNode + "\", \"type\" ***and junk*** : \"LOVES\"}" ); assertEquals( 400, response.getStatus() ); assertEquals( Request.InvalidFormat.code().serialize(), singleErrorCode( response ) ); }
@Test public void shouldRespondWith400WhenNodeCreatedWithInvalidJSON() throws Exception { Response response = service.createNode( "this:::isNot::JSON}" ); assertEquals( 400, response.getStatus() ); assertEquals( InvalidFormat.code().serialize(), singleErrorCode( response ) ); }
@Test public void shouldRespondWith400WhenTransferringCorruptJsonPayload() throws Exception { Response response = service.setAllNodeProperties( helper.createNode(), "{\"foo\" : bad-json-here \"bar\"}" ); assertEquals( 400, response.getStatus() ); assertEquals( Request.InvalidFormat.code().serialize(), singleErrorCode( response ) ); }
@Test public void shouldRespondWith400WhenSettingRelationshipPropertyWithBadJson() throws Exception { long relationshipId = helper.createRelationship( "KNOWS" ); String json = "}Mattias"; Response response = service.setRelationshipProperty( relationshipId, "name", json ); assertEquals( 400, response.getStatus() ); assertEquals( Request.InvalidFormat.code().serialize(), singleErrorCode( response ) ); }
@Test public void shouldRespondWith400ForSetNodePropertyWithInvalidJson() throws Exception { String key = "foo"; String json = "{invalid json"; Response response = service.setNodeProperty( 999999, key, json ); assertEquals( 400, response.getStatus() ); assertEquals( Request.InvalidFormat.code().serialize(), singleErrorCode( response ) ); }